import formJs from "./regexDetail.js"; //新增弹框配置项
import TableData from "@/components/public/el-table"; //主页面列表
import TableLyout from '@/components/commonPublic/tableLyout.vue'

import {
    getWbsList, //WBSWBS
} from "@/api/request.js";

export default {
    props: [
        "dialogVisible",
        "fCompanyid"
    ],
    data() {
        return {
            visible: "",
            queryCriteriaData: {}, //分页
            searchObj: formJs.searchObj, //搜索条件
            table_config: formJs.table_config, //列表
            materialInfo_config: formJs.materialInfo_config,
            tableData_Wbs: [],
            // 列表
            getList: {
                page: 1,
                pageSize: 10,
                fId: ""
                // name: "", //材料种类/名称
                // fVersion: "" //规格型号
            },
            loading: false,
            materialData: [], //种类数据
            tableData: [],
            title: null,
            isLock: false,
            dialogHeight: null,
            activeIndex: "1",
            btnShow: true,
            WbsRow: null,
            types: null,
        };
    },
    components: {
        // publicForm,
        TableLyout,
        TableData,
        // publicForm1
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        fCompanyid:{
            handler(newVal) {
                if (newVal) {
                    this.yj_searchForm(newVal, "");
                }
            },
            immediate: true,
        },
    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {
        this.btnShow = true
        this.getToken();
        this.getHeight();
    },
    methods: {
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.76 + "px";
        },
        closeDialog1() {
            this.$emit("close1");
        },

        rowChange1(val) {
            this.getList.fId = val.fVarietyid;
            this.types = val
            this.yj_searchForm(this.getList)
        },
        // 点击材料
        rowChange(val) {
            this.WbsRow = val
            // this.dataFid = val.fId;
        },
        // WBS
        async getToken() {
            await this.$http(
                "http://1.14.103.201:8300/IOTManagement/roadApi/getToken.do"
            ).then((res) => {
                if (res.status == 200) {
                    sessionStorage.setItem("yjSmart-token", res.data.data.Authorizations);
                    this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));
                   
                }
            });
        },
        // 获取列表数据
        yj_searchForm(id) {
            this.visible = true;
            this.load = true;
            getWbsList({
                    // fCompanyid: "ed1bd59e-575a-4053-b23d-1bb22c49479d",
                    // fCompanyid: id, //云检的标段Id
                    // fNodeId: num, //WBS节点Id（对应返回数据中的NodeId字段），该参数可以不传或为空（不传或为空代表的是获取第一层的WBS数据），如果该参数传了值，则代表的是获取该节点的下一层的所有数据
                    // keyWord: "", //工程部位查询关键字

                    fCompanyid: id, //标段id 必填
                    projectId: "", //项目id 必填
                    parentId: "-1" //父级id 第一级传-1  子级取上一级fId或fNodeid 必填
                })
                .then((res) => {
                    if (res.errcode == 0) {
                        if(res.data.data.length!=0){
                            this.tableData_Wbs = res.data.data;
                            this.loading = false;
                        }else {
                        //    this.$message.warning("您暂无WBS树");
                        }
                       
                    } else {
                        this.$message.error(res.msg);
                        this.loading = false;
                    }
                })
                .catch((error) => {
                    this.$message.error(error.msg);
                    this.loadingEditDialog_wbs = false;
                });
        },
        treeLoad(tree, treeNode, resolve) {
            console.log(tree, treeNode, resolve);
            getWbsList({
                    // fCompanyid: tree.fCompanyid, //云检的标段Id
                    // fNodeId: tree.fNodeid, //WBS节点Id（对应返回数据中的NodeId字段），该参数可以不传或为空（不传或为空代表的是获取第一层的WBS数据），如果该参数传了值，则代表的是获取该节点的下一层的所有数据
                    // keyWord: "", //工程部位查询关键字
                    fCompanyid: tree.fCompanyid, //标段id 必填
                    projectId: "", //项目id 必填
                    parentId: tree.fId//父级id 第一级传-1  子级取上一级fId或fNodeid 必填
                })
                .then((res) => {
                    if (res.errcode == 0) {
                        return resolve(res.data.data);
                    } else {
                        this.$message.error(res.msg);
                    }
                })
                .catch((error) => {
                    this.$message.error(error.msg);
                    this.loading = false;
                });
        },
        // 点击当前行变色
        handleCurrentChange(val) {
            this.WbsRow = val;
        },
        // 行颜色
        tableRowClassName({
            row
        }) {
            if (
                (row.fParentid == 0 && !row.children) ||
                (row.fParentid == null && !row.children)
            ) {
                return "fristColor";
            }
        },
        yj_saveForm() {
            if (this.WbsRow != null) {
                this.$emit('getWBS', this.WbsRow, this.types)
                this.visible = false
            } else {
                this.$message.error('请先选择工程部位');

            }
        },

    },
};